using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DTO;

namespace DAO
{
    public class HoaDonDAO:DataProvider
    {
        public void Them(HoaDonDTO hddto)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.KetNoi();
            string str = "Insert into HoaDon(TriGia, MaNV, MaKH,NgayXuat) values (?, ?, ?, ?)";

            OleDbCommand cmd = new OleDbCommand(str, cn);

            cmd.Parameters.Add("@TriGia", OleDbType.Integer);
            cmd.Parameters.Add("@MaNV", OleDbType.Integer);
            cmd.Parameters.Add("@MaKH", OleDbType.Integer);
            cmd.Parameters.Add("@NgayXuat", OleDbType.Date);

            cmd.Parameters["@TriGia"].Value = hddto.TriGia;
            cmd.Parameters["@MaNV"].Value = hddto.MaNV;
            cmd.Parameters["@MaKH"].Value = hddto.MaKH;
            cmd.Parameters["@NgayXuat"].Value = hddto.NgayXuat;

            cmd.ExecuteNonQuery();

            cn.Close();
        }
        public DataTable LayMaxMa()
        {
            string sql = "select Max(Ma) from HoaDon";
            return DocBang(sql);
        }
        public void ThemChiTiet(DataTable dt, int mahd)
        {
            string sql = "select * from ChiTietHD where MaHD=" + mahd.ToString();
            UpdateBang(sql, dt);
        }
        public DataTable LayBangChiTietHD(int mahd)
        {
            string sql = "select * from ChiTietHD where MaHD=" + mahd.ToString();
            return DocCauTruc(sql);
        }
        public DataTable BaoCaoHoaDon(string sql)
        {
            DataTable dt = DocBang(sql);
            return dt;
        }
    }
}
